package reflect;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;

/**
 * 获取Pereson类中的所有方法，判断，若方法被AutoRunMethod注解修饰，则调用该方法，否则提示
 */
public class Test3 {
    public static void main(String[] args) throws Exception {
        Class cls = Class.forName("reflect.Person");
        Constructor constructor = cls.getConstructor(String.class,int.class);
        Object obj = constructor.newInstance("沙金航",1000);
        Method[] methods = cls.getDeclaredMethods();
        for (Method method:methods){
            if (method.isAnnotationPresent(AutoRunMethod.class)){
                System.out.println("调用方法"+method.getName()+"()");
                method.invoke(obj);
            }else {
                System.out.println(method.getName()+"()方法未被注解");
            }
        }

    }
}
